<?php
class Application_Model_User extends App_DbTable
{
	
	public function __construct($id = null){
		parent::__construct(new Application_Model_DbTable_User(), $id);
	}
	public function fill($data = array()){
		foreach ($data as $key => $value){
			$this->$key = $value;
		}
		$this->password = sha1($data['password']);
	}
	public function getBets($limit = 0){
		$select = $this->_dbTable->select();
		$select->order('date_add DESC');
		if($limit){
			$select->limit($limit);
		}
		$bets = array();		
		$rowset = $this->_row->findDependentRowset('Application_Model_DbTable_Bet', 'User', $select);
		foreach ($rowset as $row){
			$bets[] = new Application_Model_Bet($row->id);
		}
		return $bets;
	}
	public function countPoints(){
		$points = 0;
		$rowset = $this->_row->findDependentRowset('Application_Model_DbTable_Bet', 'User');
		foreach ($rowset as $row){
			$points += $row->points;
		}
		return $points;
	}
}